var express = require("express");
var cookieParser  = require("cookie-parser");

var app = express();
app.use(cookieParser());        // cookie中间件 

app.get("/",function(req,res){
    res.send("猜你喜欢---" + req.cookies.location);
});

// 查询，语法 http://127.0.0.1/gonglue?location=陈伟霆  此时陈伟霆就能记录在cookie中
app.get("/gonglue",function(req,res){
    var location = req.query.location;          // 得到请求，用户查询到额目的地
    var locationArray = req.cookies.location || [];         // 第一次cookie会是空的
    locationArray.push(location);
    res.cookie("location", locationArray,{maxAge:900000,httpOnly:true});
    res.send(location +"旅游攻略");
});

app.listen(3000);